﻿''' <summary>
''' Class that allows you to perform a case insensitive search on portions of a media file's properties to see if it is a podcast based on
''' strings contained therein, as defined by Podcast.ini
''' </summary>
Public Class IsPodcast
  Private _FilePath As String = ""
  Private _Artist As String = ""
  Private _AlbumArtist As String = ""
  Private _Title As String = ""
  Private _Album As String = ""
  Private _Genre As String = ""
  Private _Comments As String = ""

  Private _UseFilePath As Boolean = False
  Private _UseArtist As Boolean = False
  Private _UseAlbumArtist As Boolean = False
  Private _UseTitle As Boolean = False
  Private _UseAlbum As Boolean = False
  Private _UseGenre As Boolean = False
  Private _UseComments As Boolean = False

  Private _PodcastStrings As New List(Of String)

  Public Sub New()
    ' Flag the search fields
    Me._UseFilePath = Settings.PodcastSearchInFilePath
    Me._UseArtist = Settings.PodcastSearchInArtist
    Me._UseAlbumArtist = Settings.PodcastSearchInAlbumArtist
    Me._UseTitle = Settings.PodcastSearchInTitle
    Me._UseAlbum = Settings.PodcastSearchInAlbum
    Me._UseGenre = Settings.PodcastSearchInGenre
    Me._UseComments = Settings.PodcastSearchInComments

    ' Import the search strings
    For Each s As String In Settings.PodcastSearchTerms
      s = s.Trim
      If s.Length > 0 Then
        Me._PodcastStrings.Add(s.ToLower)
      End If
    Next
  End Sub

  Public Property FilePath() As String
    Get
      Return Me._FilePath
    End Get
    Set(ByVal value As String)
      Me._FilePath = value.ToLower()
    End Set
  End Property

  Public Property Artist() As String
    Get
      Return Me._Artist
    End Get
    Set(ByVal value As String)
      Me._Artist = value.ToLower()
    End Set
  End Property

  Public Property AlbumArtist() As String
    Get
      Return Me._AlbumArtist
    End Get
    Set(ByVal value As String)
      Me._AlbumArtist = value.ToLower()
    End Set
  End Property

  Public Property Title() As String
    Get
      Return Me._Title
    End Get
    Set(ByVal value As String)
      Me._Title = value.ToLower()
    End Set
  End Property

  Public Property Album() As String
    Get
      Return Me._Album
    End Get
    Set(ByVal value As String)
      Me._Album = value.ToLower()
    End Set
  End Property

  Public Property Genre() As String
    Get
      Return Me._Genre
    End Get
    Set(ByVal value As String)
      Me._Genre = value.ToLower()
    End Set
  End Property

  Public Property Comments() As String
    Get
      Return Me._Comments
    End Get
    Set(ByVal value As String)
      Me._Comments = value.ToLower()
    End Set
  End Property

  Public ReadOnly Property IsPodcast() As Boolean
    Get
      Dim search As New System.Text.StringBuilder()
      Dim searchString As String

      If Me._UseFilePath Then
        search.AppendLine(Me._FilePath)
      End If
      If Me._UseArtist Then
        search.AppendLine(Me._Artist)
      End If
      If Me._UseAlbumArtist Then
        search.AppendLine(Me._AlbumArtist)
      End If
      If Me._UseTitle Then
        search.AppendLine(Me._Title)
      End If
      If Me._UseAlbum Then
        search.AppendLine(Me._Album)
      End If
      If Me._UseGenre Then
        search.AppendLine(Me._Genre)
      End If
      If Me._UseComments Then
        search.AppendLine(Me._Comments)
      End If

      searchString = search.ToString

      For Each s As String In Me._PodcastStrings
        If searchString.Contains(s) Then
          Return True
        End If
      Next

      Return False
    End Get
  End Property
End Class
